﻿@{
    Layout = null;
    var moduleSEModel = ViewBag.moduleSEModel as NB.MGJ.Model.Origins_ModuleSE;
    var materialModel = ViewBag.materialModel as NB.MGJ.Model.Origins_Material;
    var exDic = ViewBag.exDic as Dictionary<string, string>;
}
@*标准版*@
<link href="~/Content/TraceSource/main.css" rel="stylesheet" />
<link href="~/Content/TraceSource/ExperienceCenter.css" rel="stylesheet" />
<link href="~/Content/TraceSource/S_Gpublic.css" rel="stylesheet" />
<style>
    #contentDiv
    {
        margin-top: 50px !important;
    }

    #edui1
    {
        width: 100% !important;
    }

    #edui1_iframeholder
    {
        width: 100% !important;
    }

    .RichWrap img
    {
        width: 100%;
    }

    .new-contentarea:hover .nb-btn-success-hover
    {
        background-color: #79bf79 !important;
    }
</style>
<!--右侧浮动-->
<div id="fixed_right">
    <div class="glyphicon glyphicon-chevron-left m-r-xs fixed_right_hover fixed_right_icon" style="display:none"></div>
    <div>
        <div class="glyphicon glyphicon-chevron-right m-r-xs fixed_right_hover fixed_right_icon"></div>
        <!-- <div class="fixed_right fixed_right_hover">返回</div> -->
        <div class="fixed_right fixed_right_hover" id="scyl" name="scyl" onclick="$.MGJ.Common._PrewView(@materialModel.MaterialId, 0);">预览</div>
        <div class="fixed_right fixed_right_hover" onclick="UrlBack()">返回</div>
    </div>
</div>
<div class="wrapper wrapper-content fadeInRight m-pagecontent">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <ul class="phone-ul clearfix">
                        <li class="col-lg-6 phone-model m-pageleft">
                            <div class="model-bar model-m">
                                <div class="phone-bar phone-bar-m">
                                    <h3 class="phone-title">
                                        <span class="iconfont icon-jiantou1 back-icon">
                                        </span> 产品详情
                                    </h3>
                                    <div class="phone-con-bar  phone-con-bar-m">
                                        @if (moduleSEModel.Picture == "")
                                        {
                                            <img src="~/Content/webImgs/TraceSource/TraceSourceEdit/product-logo-default.png" class="phone-pro-pic show-img" />
                                        }
                                        else
                                        {
                                            <img src="@moduleSEModel.Picture" class="phone-pro-pic show-img" />
                                        }

                                        <div class="phone-pro-name-bar">
                                            <h3 class="phone-pro-name" style="display:inline-block;">产品名称：</h3>
                                            <h3 class="phone-pro-name" id="phone-product-name" style="display:inline-block;">@moduleSEModel.ProductName</h3>
                                        </div>
                                        <div class="format-bar">
                                            规格参数
                                        </div>
                                        <ul class="format-ul clearfix ">
                                            <li>
                                                <span class="format-name">产品编号：</span>
                                                <span class="format-con" id="phone-product-bar">@moduleSEModel.ProductCode</span>
                                            </li>
                                            <li>
                                                <span class="format-name">产地：</span>
                                                <span class="format-con" id="phone-product-place">@moduleSEModel.ProduceArea</span>
                                            </li>
                                            <li>
                                                <span class="format-name">规格：</span>
                                                <span class="format-con" id="phone-product-format">@moduleSEModel.Format</span>
                                            </li>

                                            @if (exDic != null && exDic.Count > 0)
                                            {
                                                foreach (KeyValuePair<string, string> item in exDic)
                                                {
                                                    <li class="mobile-hidden-li mobile-show-li">
                                                        <span class="format-name">@item.Key：</span>
                                                        <span class="format-con">@item.Value</span>
                                                    </li>
                                                }
                                            }
                                            <li class="RichWrap">
                                                @Html.Raw(moduleSEModel.ShortDescription)
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </li>
                        <li class="col-lg-6 m-pageright">
                            <form class="error-tips-bottom create-product" id="create-form" method="POST" novalidate="novalidate">
                                <ul class="create-ul create-w">

                                    <li>
                                        <p class="input-title create-ul-h5">
                                            产品名称
                                            <span class="red-color">*</span>
                                        </p>
                                        <input value="@moduleSEModel.ProductName" type="text" placeholder="请输入不超过30个字的产品名称" class="form-control input-lg input-in create-inp create-inp-num" maxlength="30" id="product-name" name="name"><span class="inp-num" id="product-name-num">0/30</span>
                                    </li>
                                    <li>
                                        <p class="input-title create-ul-h5">
                                            产品编号<span class="red-color">*</span>
                                        </p>
                                        <input value="@moduleSEModel.ProductCode" type="text" placeholder="请输入不超过13位的产品编号" class="form-control input-lg input-in create-inp create-inp-num" maxlength="13" id="product-bar" name="bar_code">
                                        <span class="inp-num" id="product-bar-num">0/13</span>
                                    </li>
                                    <li>
                                        <p class="input-title create-ul-h5">
                                            产地
                                            <span class="red-color">*</span>
                                        </p>
                                        <input value="@moduleSEModel.ProduceArea" type="text" placeholder="请输入产品的生产地址" class="form-control input-lg input-in create-inp" id="product-place" name="address">
                                    </li>
                                    <li>
                                        <p class="input-title create-ul-h5">
                                            规格<span class="red-color">*</span>
                                        </p>
                                        <input value="@moduleSEModel.Format" type="text" placeholder="请输入产品的规格" class="form-control input-lg input-in create-inp" id="product-format" name="specification">
                                    </li>
                                    <li>
                                        <div class="upload-product-box">
                                            <p class="clearfix input-title input-title-img form-label-title">
                                                <span class="pull-left">图片<span class="red-text">*</span></span>
                                            </p>
                                            <div class="imageBox verify-show file-inp-bar">
                                                <div class="thumbBox"></div>
                                                <div class="spinner" style="">
                                                    Loading...
                                                </div>
                                            </div>
                                            <div class="note">
                                                （请选择大小不超过2M的图片）
                                            </div>
                                            <div class="action upload-file-img clearfix">
                                                <div class="new-contentarea file-inp-bar tc">
                                                    <a href="javascript:void(0)" class="upload-img nb-btn-css nb-btn-success-hover"><label for="upload-file">上传图片</label></a><input type="file" class="upload-file-cropper" name="upload_file" id="upload-file">
                                                </div>
                                                <input type="button" id="btnZoomIn" class="Btnsty_peyton pull-left nb-btn-css nb-btn-success-hover" value="+"><input type="button" id="btnZoomOut" class="Btnsty_peyton pull-left nb-btn-css nb-btn-success-hover" value="-"><input type="button" id="btnCrop" class="Btnsty_peyton special-width pull-right nb-btn-css nb-btn-success-hover" value="确定裁切">
                                            </div>
                                        </div>
                                    </li>

                                    <li style="text-align:center;margin-bottom:10px">
                                        <script id="editor" type="text/plain">
                                        </script>
                                    </li>



                                    @if (exDic != null && exDic.Count > 0)
                                    {

                                        foreach (KeyValuePair<string, string> item in exDic)
                                        {
                                            <li class="newadd-li">
                                                <div class="input-group create-w">
                                                    <input value="@item.Key" type="text" class="form-control newadd valid" name="more_title" maxlength="10" placeholder="添加标题">
                                                    <span class="input-group-btn"><button type="button" class="btn btn-danger newadd-remove">删除</button></span>
                                                </div>
                                                <input value="@item.Value" type="text" placeholder="请输入想添加的内容" maxlength="30" name="more_con" class="form-control input-lg newadd-con valid">
                                            </li>
                                        }
                                    }
                                    <button type="button" class="btn btn-block btn-success newadd-button nb-btn-margin-tb">＋添加其他信息</button>
                                    <button type="submit" class="btn btn-block btn-success nb-btn-margin-tb nb-btn-success-hover" onclick="imgFormCheck()">保存</button>
                                </ul>
                            </form>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>
<li class="hidden newadd-li">
    <div class="input-group create-w">
        <input type="text" class="form-control newadd" name="more_title" maxlength="10" placeholder="添加标题">
        <span class="input-group-btn"><button type="button" class="btn btn-outline btn-danger newadd-remove">删除</button></span>
    </div>
    <input type="text" placeholder="请输入想添加的内容" maxlength="30" name="more_con" class="form-control input-lg newadd-con">
</li>
<li class="hidden mobile-hidden-li">
    <span class="format-name"></span>
    <span class="format-con"></span>
</li>
<input id="short" type="hidden" value="@moduleSEModel.ShortDescription" />

<script src="~/Scripts/MGJJS/TraceSource/PageOperation/jquery.qrcode.min.js"></script>
<script src="~/Scripts/MGJJS/TraceSource/PageOperation/jquery.validate.min.js"></script>
<script src="~/Scripts/MGJJS/TraceSource/PageOperation/cropbox.js"></script>
<script src="~/Scripts/MGJJS/TraceSource/PageOperation/sec1.js"></script>

<script src="~/Scripts/MGJJS/TraceSource/PageOperation/UEditor/ueditor.config.js"></script>
<script src="~/Scripts/MGJJS/TraceSource/PageOperation/UEditor/ueditor.all.js"></script>
<script src="~/Scripts/MGJJS/TraceSource/PageOperation/UEditor/lang/zh-cn/zh-cn.js"></script>

<script>
    var ue = UE.getEditor('editor');
    var sh = $("#short").val();
    ue.addListener("ready", function () {
        ue.setContent(sh);
    });
    ue.addListener("contentChange", function () {
        $(".RichWrap").html(ue.getContent());
    });
</script>

<script>

    $(function () {

        function e() {

            for (var e = {}, n = new FormData, a = $(".newadd"), t = $(".newadd-con"), r = 0; r < a.length; r++) {
                a[r].value && t[r].value && (e[a[r].value] = t[r].value);
            };
            
            var short = ue.getContent();
            n.append("ModuleId", '@moduleSEModel.ModuleId'),
            n.append("ShortDescription", short),
            n.append("ProductName", $("#product-name").val()),
            n.append("ProductCode", $("#product-bar").val()),
            n.append("ProduceArea", $("#product-place").val()),
            n.append("Format", $("#product-format").val()),
            n.append("ExtendInfo", JSON.stringify(e)),
            n.append("Picture", cropper.getBlob(), "blob.png"),
            //console.log(cropper.getBlob()),
            $.ajax({
                url: "/OriginsMaterial/ModuleSESave",
                timeout: 5e3,
                type: "POST",
                async: !1,
                crossDomain: !0,
                xhrFields: {
                    withCredentials: !0
                },
                processData: !1,
                contentType: !1,
                data: n,
                context: $("#create-form"),
                success: function (e) {
                    $.L.msgSuccess("保存成功")
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    $.L.msgError(jqXHR.responseText);
                }
            })
        };
        //input 产品名称产品编号 长度控制
        $(".create-inp").keyup(function (e) {
            $("#phone-product-name").html($("#product-name").val());
            var n = $("#product-name").val().length;
            $("#product-name-num").html(n + "/30"), $("#phone-product-bar").html($("#product-bar").val());
            var a = $("#product-bar").val().length;
            //$("#product-bar-num").html(a + "/13"), $("#phone-product-place").html($("#product-place").val()), $("#phone-product-format").html($("#product-format").val()), "" == $("#product-name").val() && $("#phone-product-name").html("产品名称")
            $("#product-bar-num").html(a + "/13"), $("#phone-product-place").html($("#product-place").val()), $("#phone-product-format").html($("#product-format").val()), "" == $("#product-name").val()
        })

        deal_cropper(),//图片裁剪
        $("div.upload-product-box").get(0).addEventListener("mousewheel", removeWheelEvent, !1),
        $(".newadd-button").click(function () {

            var e = $(".newadd-li.hidden").clone();
            e.removeClass("hidden"), $(this).before(e), new_more_info()
        }),
        $("body").on("click", ".newadd-remove", function () {
            isIE() ? $(this).parents("li")[0].removeNode(!0) : $(this).parents("li")[0].remove(), change_more_info()
        }),
        $("body").on("change", ".newadd", function () {
            change_more_info()
        }),
        $("body").on("change", ".newadd-con", function () {
            change_more_info()
        })
        $("#create-form").validate({
            ignore: "",
            rules: {
                brand_id: {
                    required: !0
                },
                name: {
                    required: !0,
                    maxlength: 30
                },
                bar_code: {
                    required: !0,
                    maxlength: 13,
                    numberAndLettersVal:13
                },
                address: {
                    required: !0,
                    maxlength: 30
                },
                specification: {
                    required: !0,
                    maxlength: 20
                },
                //upload_file: {
                //    required: !0,
                //    checkSize: 2
                //}
            },
            messages: {
                brand_id: {
                    required: "请选择批次"
                },
                name: {
                    required: "请输入不超过30个字的产品名称",
                    maxlength: "请输入不超过30个字的产品名称"
                },
                bar_code: {
                    required: "请输入不超过13位的产品编号",
                    maxlength: "请输入不超过13位的产品编号"
                },
                address: {
                    required: "请输入不超过30个字的产品生产地址",
                    maxlength: "请输入不超过30个字的产品生产地址"
                },
                specification: {
                    required: "请输入不超过20个字的产品的规格",
                    maxlength: "请输入不超过20个字的产品的规格"
                },
                //upload_file: {
                //    required: "请上传大小不超过2M的图片",
                //    checkSize: "请上传大小不超过2M的图片"
                //}
            },
            errorPlacement: jquery_valid_errorPlacement,
            success: jquery_valid_success,
            highlight: jquery_valid_highlight,
            onfocusout: jquery_valid_onfocusout,
            invalidHandler: jquery_valid_invalidHandler,
            onkeyup: !1,
            focusInvalid: !0,
            errorElement: "span",
            submitHandler: function (n) {
                
                e();

            }
        })
    });

    jQuery.validator.addMethod("numberAndLettersVal", function (value, element) {
        return this.optional(element) || /^[a-zA-Z0-9]+$/.test(value);
        }, $.validator.format("请输入13位以内的字母或数字")
    );

    //阻止事件冒泡
    function removeWheelEvent(e) {
        return e.stopPropagation(), e.preventDefault(), e.cancelBubble = !1, !1
    }

    function change_more_info() {

        $(".mobile-show-li").remove();
        for (var e = $(".newadd"), n = $(".newadd-con"), a = 0; a < e.length; a++) if (e[a].value || n[a].value) {
            var t = $(".mobile-hidden-li.hidden").clone();
            t.removeClass("hidden"), t.addClass("mobile-show-li"), t.find("span.format-name").text(e[a].value + "："), t.find("span.format-con").text(n[a].value), $(".format-ul").append(t)
        }
    }
    function new_more_info() {
        var e = $(".mobile-hidden-li.hidden").clone();
        e.removeClass("hidden"), e.addClass("mobile-show-li"), e.find("span.format-name").text("新增："), e.find("span.format-con").text(""), $(".format-ul").append(e)
    }

   
</script>

